package org.jeecg.report.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.qis.entity.QisSpcdetailCfg;
import org.jeecg.qis.service.IQisSpcdetailCfgService;
import org.jeecg.qis.service.IQisSpcheadCfgService;
import org.jeecg.report.dto.QisSpcChartDataDTO;
import org.jeecg.report.entity.QisSpcGroupData;
import org.jeecg.report.entity.QisSpcPointValue;
import org.jeecg.report.mapper.AvailabilityReportMapper;
import org.jeecg.report.mapper.QisSpcMapper;
import org.jeecg.report.service.AvailabilityReportService;
import org.jeecg.report.service.IQisSpcService;
import org.jeecg.report.utils.QisSpcUtil;
import org.jeecg.report.vo.QisSpcParameterVO;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AvailabilityReportServiceImpl implements AvailabilityReportService {
    @Resource
    private AvailabilityReportMapper availabilityReportMapper;

    @Override
    public List<QisSpcPointValue> getAvailability(Map<String, Object> params) {
        String dimension = params.get("dimension").toString();
        if (dimension.equals("hour")){
            List<QisSpcPointValue> availabilityHour = availabilityReportMapper.getAvailabilityHour(params);
            availabilityHour.forEach(item->{
                if (item.getValue().compareTo(BigDecimal.valueOf(100)) > 0){
                    item.setValue(BigDecimal.valueOf(100));
                }
            });
            return availabilityHour;
        }else{
            List<QisSpcPointValue> availabilityDay = availabilityReportMapper.getAvailabilityDay(params);
            availabilityDay.forEach(item->{
                if (item.getValue().compareTo(BigDecimal.valueOf(100)) > 0){
                    item.setValue(BigDecimal.valueOf(100));
                }
            });
            return availabilityDay;
        }
    }
}
